package goover.unit03;
import java.util.Comparator;
import java.util.TreeSet;

public class TreeSetDemo03 {
    public static void main(String[] args){
        TreeSet ts = new TreeSet(new MyComparator());
        ts.add("Jack");
        ts.add("Helena");
        ts.add("Eve");
        System.out.println(ts);
        TreeSet ts2 = new TreeSet((o1,o2) ->{
            String s1 = (String)o1;
            String s2 = (String)o2;
            return s2.length() - s1.length();
        });
        ts2.add("Jack");
        ts2.add("Helena");
        ts2.add("Eve");
        System.out.println(ts2);
    }
}
class MyComparator implements Comparator {
    @Override
    public int compare(Object o1, Object o2) {
        String s1 = (String)o1;
        String s2 = (String)o2;
        int temp = s1.length() - s2.length();
        return temp;
    }
}